﻿using System.Collections.Generic;
using System.Diagnostics;
using System.IO;

namespace MidasGtsExporter
{
	public static class IO
	{
		public static bool IsFolderExist(string folder)
			=> !string.IsNullOrEmpty(folder) && Directory.Exists(folder);

		public static bool IsFileExist(string filePath)
			=> (!string.IsNullOrEmpty(filePath)) && File.Exists(filePath);
	}

	public static class LinqExtension
	{
		public static IEnumerable<List<T>> GetSlices<T>(this IEnumerable<T> source, int n)
		{
			Debug.Assert(n > 0);
			var it = source.GetEnumerator();
			var i = 0;
			var slice = new List<T>(n);
			while (true)
			{
				var notToEnd = it.MoveNext();
				if (!notToEnd)
				{
					if (slice.Count > 0)
						yield return slice;

					yield break;
				}

				i++;
				slice.Add(it.Current);
				if (i == n)
				{
					yield return slice;

					i = 0;
					slice = new List<T>(n);
				}
			}
		}
	}
}